home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / json / tests / test_tool.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  3KB  |  49 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. import os
  5. import sys
  6. import textwrap
  7. import unittest
  8. import subprocess
  9. from test import test_support
  10. from test.script_helper import assert_python_ok
  11.  
  12. class TestTool(unittest.TestCase):
  13.     data = '\n\n        [["blorpie"],[ "whoops" ] , [\n                                 ],\t"d-shtaeou",\r"d-nthiouh",\n        "i-vhbjkhnth", {"nifty":87}, {"morefield" :\tfalse,"field"\n            :"yes"}  ]\n           '
  14.     expect = textwrap.dedent('    [\n        [\n            "blorpie"\n        ],\n        [\n            "whoops"\n        ],\n        [],\n        "d-shtaeou",\n        "d-nthiouh",\n        "i-vhbjkhnth",\n        {\n            "nifty": 87\n        },\n        {\n            "field": "yes",\n            "morefield": false\n        }\n    ]\n    ')
  15.     
  16.     def test_stdin_stdout(self):
  17.         proc = subprocess.Popen((sys.executable, '-m', 'json.tool'), stdin = subprocess.PIPE, stdout = subprocess.PIPE)
  18.         (out, err) = proc.communicate(self.data.encode())
  19.         self.assertEqual(out.splitlines(), self.expect.encode().splitlines())
  20.         self.assertEqual(err, None)
  21.  
  22.     
  23.     def _create_infile(self):
  24.         infile = test_support.TESTFN
  25.         with open(infile, 'w') as fp:
  26.             self.addCleanup(os.remove, infile)
  27.             fp.write(self.data)
  28.         return infile
  29.  
  30.     
  31.     def test_infile_stdout(self):
  32.         infile = self._create_infile()
  33.         (rc, out, err) = assert_python_ok('-m', 'json.tool', infile)
  34.         self.assertEqual(out.splitlines(), self.expect.encode().splitlines())
  35.         self.assertEqual(err, '')
  36.  
  37.     
  38.     def test_infile_outfile(self):
  39.         infile = self._create_infile()
  40.         outfile = test_support.TESTFN + '.out'
  41.         (rc, out, err) = assert_python_ok('-m', 'json.tool', infile, outfile)
  42.         self.addCleanup(os.remove, outfile)
  43.         with open(outfile, 'r') as fp:
  44.             self.assertEqual(fp.read(), self.expect)
  45.         self.assertEqual(out, '')
  46.         self.assertEqual(err, '')
  47.  
  48.  
  49.